# Contributor: Patrycja Rosa <alpine@ptrcnull.me>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=headscale
pkgver=0.15.0
pkgrel=2
pkgdesc="An open source, self-hosted implementation of the Tailscale control server"
url="https://github.com/juanfont/headscale"
arch="all !ppc64le !riscv64" # go build fails
license="BSD-3-Clause"
pkgusers="headscale"
pkggroups="headscale"
makedepends="go"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install"
source="https://github.com/juanfont/headscale/archive/v$pkgver/headscale-$pkgver.tar.gz
	headscale.initd
	"

prepare() {
	default_prepare

	# move socket to a subdirectory to allow running as non-root
	sed -i 's|/var/run/headscale.sock|/var/run/headscale/headscale.sock|' config-example.yaml
}

build() {
	make build
}

check() {
	make test
}

package() {
	install -Dm755 headscale "$pkgdir"/usr/bin/headscale

	install -Dm755 "$srcdir"/headscale.initd "$pkgdir"/etc/init.d/headscale
	install -Dm644 config-example.yaml "$pkgdir"/etc/headscale/config.yaml
}

sha512sums="
29b867f109e48bf04ab4f8a81bfab94155050f59f6c2aa2b4971567a7fb24ed343b869636e66e9cbb7b1b8df7d7415e769a85a7c3864d0fae169c15b6c7b6eb2  headscale-0.15.0.tar.gz
0800829bfc087af283afc117406324a0129b30b587c8cc5df85e147ac09fc879d726fc2d0b62ed545fb0190ed887641f07256745da9dea56932dd2d90aa41625  headscale.initd
"
